<template>
  <div class="pagination-container">
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :total="total"
      :page-sizes="[10, 20, 30, 50]"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";

const props = defineProps<{
  total: number;
  page: number;
  limit: number;
}>();

const emit = defineEmits<{
  (e: "update:page", value: number): void;
  (e: "update:limit", value: number): void;
  (e: "pagination", params: { page: number; limit: number }): void;
}>();

const currentPage = computed({
  get: () => props.page,
  set: (val) => emit("update:page", val),
});

const pageSize = computed({
  get: () => props.limit,
  set: (val) => emit("update:limit", val),
});

const handleSizeChange = (val: number) => {
  emit("pagination", { page: currentPage.value, limit: val });
};

const handleCurrentChange = (val: number) => {
  emit("pagination", { page: val, limit: pageSize.value });
};
</script>

<style lang="scss" scoped>
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;

  @media screen and (max-width: 768px) {
    :deep(.el-pagination__sizes) {
      display: none;
    }
  }
}
</style>
